/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package com.by.controller;

import com.by.common.bean.PageBean;
import com.by.common.bean.Result;
import com.by.common.controller.BaseController;
import com.by.common.group.Save;
import com.by.pojo.PurApplication;
import com.by.server.PurApplicationServer;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>Project: erp-cloud-api - PurApplicationController</p>
 * <p>Powered by yzc On 2024-01-09 11:42:24</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@RestController
@RequestMapping("/v1/pur")
@Slf4j
@Api(tags = "采购申请管理")
public class PurApplicationController extends BaseController {
    @Autowired
    PurApplicationServer purApplicationServer;

    @ApiOperation("保存采购申请")
    @PostMapping("/save")
    public Result PurApplicationSave(@Validated(value = {Save.class}) @RequestBody PurApplication purApplication,
                                     BindingResult result) {
        validator(result);
        int rs = purApplicationServer.insert(purApplication);
        if (rs > 0)
            return Result.success("采购申请保存成功");
        return Result.error("采购申请保存失败");
    }


    @ApiOperation("采购申请列表")
    @PostMapping("/queryList")
    public Result PurApplicationQuery(@RequestParam(value = "page", defaultValue = "1") int page,
                                      @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                      Integer inquireStatus, Integer purchaseType, String subject, String code,
                                      String begin,
                                      String end, Double totalAmount, String pojoCode) {
        PageBean pageBean = purApplicationServer.queryPageList(page, pageSize, subject, code, begin, end, purchaseType, totalAmount, inquireStatus, pojoCode);
        return Result.success(pageBean);
    }


    @ApiOperation("采购申请明细列表")
    @PostMapping("/list")
    public Result list(@RequestParam(value = "page", defaultValue = "1") int page,
                       @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                       String pojoCode, String proName, String proCode, String supCode, Double totalAmount,
                       Integer inquireStatus, Integer applicationStatus, String subject, String begin, String end,
                       Integer purchaseType
    ) {
        PageBean pageBean = purApplicationServer.queryList(page, pageSize, pojoCode, proName, proCode, supCode, totalAmount, inquireStatus, applicationStatus, subject, begin, end, purchaseType);
        return Result.success(pageBean);
    }

}
